<?php
            $phone    = isset($_POST['phone']) ? $_POST['phone'] : '';
            $user     = isset($_POST['user']) ? $_POST['user'] : '';
            $password = isset($_POST['password']) ? $_POST['password'] : '';
            $mysqli   = new mysqli('localhost','root','123456','test');//创建对象并打开连接

    function query( $mysqli,$phone,$user,$password){

            $msg      = array("user"=>"1","phone"=>"1","win"=>"1");
            $sqlUser  = "SELECT `user` FROM `test_user` WHERE   `user` = '$user'"; //执行sql语句
            $resultS  = $mysqli->query($sqlUser);
            $rowUser  = $resultS->fetch_array();
            $sqlPhone = "SELECT `phone` FROM `test_user` WHERE   `phone` = '$phone'"; //执行sql语句
            $result   = $mysqli->query($sqlPhone);
            $rowPhone = $result->fetch_array();

        if($rowUser["user"]==''){
            $msg['user'] = 0;
            $msg['win'] ++;

        }
        if($rowPhone['phone']==''){
            $msg['phone'] = 0;
            $msg['win'] ++;
        }
        if(  $msg['win'] ==3 && $phone != ''&& $user!=''){
            $time = microtime(true);//获取程序执行结束的时间
            //echo date('Y-m-d h:i:s',time());//将时间戳转换成时间
            $password = md5($password);
            $sql = "INSERT INTO `test_user`(`user`,`password`,`time`,`phone`,`show`) VALUES ('$user','$password','$time','$phone','1')";
            $mysqli->query($sql);
            //echo '<meta http-equiv="refresh" content="0;URL=/debark.html">';
            //header("Location:http://localhost/debark.html");
           // header("refresh:3;url=http://localhost/debark.html");

        }
        echo json_encode($msg);

    }

/*登陆*/
function debark($user,$password,$mysqli){
            $msg = array("user" => '0',"password" => "0","win"=>"0");
            $sqlUser ="SELECT `user`,`phone` FROM `test_user` WHERE `user`='$user' OR `phone` = '$user'  ";
            $result = $mysqli->query($sqlUser);
            $rowUser  = $result->fetch_array();
            $password = md5($password);
            $sqlP ="SELECT `password` FROM `test_user` WHERE `password` = '$password'  ";
            $result = $mysqli->query($sqlP);
            $rowP = $result->fetch_array();
        if($rowUser['user'] != ''||$rowUser['password'] != ''){

                $msg['user'] =1;
                $msg['win'] ++;
            }
        if($rowP['password'] != ''){
                $msg['password'] =1;
                $msg['win'] ++;
            }

        echo json_encode($msg);
        }

        if($phone != ''){
                query( $mysqli,$phone,$user,$password);
            }
        else{
                debark($user,$password,$mysqli);
            }

        //print_r($row);
        // echo json_encode($msg);*/
?>
